package com.dyc.maitaole.controller;

import com.dyc.maitaole.entity.*;
import com.dyc.maitaole.service.BrandGoodService;
import com.dyc.maitaole.service.CategoryBrandService;
import com.dyc.maitaole.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/good")
public class BrandGoodController {
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private CategoryBrandService categoryBrandService;
    @Autowired
    private BrandGoodService brandGoodService;

    @RequestMapping("/goodlist")
    public ModelAndView findAllGood(Integer brandId, Integer categoryId) {
        List<Category> categories = categoryService.findAllCategories();
        List<Brand> brands = categoryBrandService.findAllBrandByCategoryId(categoryId);
        List<BrandGood> brandGoods = brandGoodService.findAllGoodByBrandId(brandId);
        int count = brandGoodService.countAllGoodByBrandId(brandId);
        ModelAndView modelAndView = new ModelAndView("/index.jsp");
        modelAndView.addObject("categories", categories);
        modelAndView.addObject("brands", brands);
        modelAndView.addObject("brandGoods", brandGoods);
        modelAndView.addObject("count", count);
        return modelAndView;
    }
}
